<?php

declare(strict_types=1);

namespace App\Admin\Controller\System\DataCenter;

use App\Admin\Annotation\Auth;
use App\Admin\Annotation\Permission;
use App\Admin\Service\System\SystemUploadFileService;
use DI\Attribute\Inject;
use Newbie\Annotation\Attributes\Route\Controller;
use Newbie\Annotation\Attributes\Route\DeleteMapping;
use Newbie\Annotation\Attributes\Route\GetMapping;
use Newbie\Annotation\Attributes\Route\PutMapping;
use Newbie\NewbieController;
use support\Request;
use support\Response;

/**
 * 文件管理控制器
 * Class UploadFileController
 * @package App\system\Controller\DataCenter
 */
#[Controller(prefix: "system/attachment"), Auth]
class AttachmentController extends NewbieController {
    #[Inject]
    protected SystemUploadFileService $service;

    /**
     * 列表数据
     * @param Request $request
     * @return Response
     */
    #[GetMapping("index"), Permission("system:attachment:index")]
    public function index (Request $request): Response {
        return $this->success($this->service->getPageList($request->all()));
    }

    /**
     * 回收站列表数据
     * @param Request $request
     * @return Response
     */
    #[GetMapping("recycle"), Permission("system:attachment:recycle")]
    public function recycle (Request $request): Response {
        return $this->success($this->service->getPageListByRecycle($request->all()));
    }

    /**
     * 单个或批量删除附件
     * @param String $ids
     * @return Response
     */
    #[DeleteMapping("delete/{ids}"), Permission("system:attachment:delete")]
    public function delete (string $ids): Response {
        return $this->service->delete($ids) ? $this->success() : $this->error();
    }

    /**
     * 单个或批量真实删除文件 （清空回收站）
     * @param String $ids
     * @return Response
     */
    #[DeleteMapping("realDelete/{ids}"), Permission("system:attachment:realDelete")]
    public function realDelete (string $ids): Response {
        return $this->service->realDelete($ids) ? $this->success() : $this->error();
    }

    /**
     * 单个或批量恢复在回收站的文件
     * @param String $ids
     * @return Response
     */
    #[PutMapping("recovery/{ids}"), Permission("system:attachment:recovery")]
    public function recovery (string $ids): Response {
        return $this->service->recovery($ids) ? $this->success() : $this->error();
    }
}
